package com.ruoyi.web.controller.douyin;

import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.DyAnchorRelVo;
import com.ruoyi.system.domain.bo.DyAnchorRelBo;
import com.ruoyi.system.service.IDyAnchorRelService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 主播所属运营
 *
 * @author ruoyi
 * @date 2024-06-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/anchorRel")
public class DyAnchorRelController extends BaseController {

    private final IDyAnchorRelService iDyAnchorRelService;

    /**
     * 查询主播所属运营列表
     */
    @SaCheckPermission("system:anchorRel:list")
    @GetMapping("/list")
    public TableDataInfo<DyAnchorRelVo> list(DyAnchorRelBo bo, PageQuery pageQuery) {
        return iDyAnchorRelService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出主播所属运营列表
     */
    @SaCheckPermission("system:anchorRel:export")
    @Log(title = "主播所属运营", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DyAnchorRelBo bo, HttpServletResponse response) {
        List<DyAnchorRelVo> list = iDyAnchorRelService.queryList(bo);
        ExcelUtil.exportExcel(list, "主播所属运营", DyAnchorRelVo.class, response);
    }

    /**
     * 获取主播所属运营详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:anchorRel:query")
    @GetMapping("/{id}")
    public R<DyAnchorRelVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iDyAnchorRelService.queryById(id));
    }

    /**
     * 新增主播所属运营
     */
    @SaCheckPermission("system:anchorRel:add")
    @Log(title = "主播所属运营", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DyAnchorRelBo bo) {
        return toAjax(iDyAnchorRelService.insertByBo(bo));
    }

    /**
     * 修改主播所属运营
     */
    @SaCheckPermission("system:anchorRel:edit")
    @Log(title = "主播所属运营", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DyAnchorRelBo bo) {
        return toAjax(iDyAnchorRelService.updateByBo(bo));
    }

    /**
     * 删除主播所属运营
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:anchorRel:remove")
    @Log(title = "主播所属运营", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iDyAnchorRelService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
